package com.activenetwork.util.verification.gson;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;

import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.EnvContext;
import com.google.gson.Gson;

public class FailureAssertion {
	private static Logger logger = LoggerFactory.getLogger(FailureAssertion.class);
	
	public static void pop(Class<? extends BaseCase> testCaseClass){
		Gson gson = new Gson();
		String caseName = testCaseClass.getSimpleName();
		List<FailurePoint> threadPoints = EnvContext.failurePointTL.get();
		List<FailurePoint> casePoints = new ArrayList<FailurePoint>();
		for(FailurePoint point : threadPoints){
			if(point.getCaseName().contains(caseName)){
				casePoints.add(point);
			}
		}
		ThreadFailurePoints points = new ThreadFailurePoints(Thread.currentThread().getName(), casePoints);
		
		if(EnvContext.failurePointTL.get().size() > 0){
			logger.error("Case: " + caseName + " => Thread: " + Thread.currentThread().getName() + " - Verification Points Failed:" + gson.toJson(points));
			Assert.fail("!!! " + caseName + " FAIL!!!");
		}else{
			logger.info("Case: " + caseName + " => Thread: " + Thread.currentThread().getName() + " - Verification Points Passed");
		}
	}
	

}
